/**
 * Created by 余保林 on 2017/8/9.
 */
import ajax from '../ajax'

const userInfo = {
  login_name: 'admin',
  role: [
    {id: 1, name: '系统管理员'}
  ],
  info: {
    name: '余保林'
  }
}

export default {
  getUserList (params, success, fail = null) {
    ajax.get({
      url: `/api/user/userList`,
      params: params,
      success,
      fail
    })
  },
  getUserInfo (cb) {
    setTimeout(() => cb(userInfo), 1000)
  },
  saveUser (userData, success, fail = null) {
    const method = userData.id === 0 ? 'post' : 'put'
    ajax[method]({url: `/api/user/${userData.id}`, data: userData, success, fail})
  },
  deleteUser (userId, success) {
    ajax.del({url: `/api/user/${userId}`, success})
  },
  deleteUsers (userIds, success) {
    ajax.del({url: `/api/user/deleteList`, data: {ids: userIds}, success})
  },
  resetPassword (userId, success) {
    ajax.put({url: `/api/user/resetPassword`, data: {userId: userId}, success})
  }
}
